using System.Xml;

namespace MessageGateway
{
    /* This channel can connect components without using a message queue.
     * The main difference is that the execution is synchronous.
     * Also, it allows multiple simultaneous subscribers, i.e. it acts as a pub-sub channel.
     */
	public class StraightThroughChannel : IMessageSender, IMessageReceiver
	{
        OnMsgEvent subscriber;

		public StraightThroughChannel()
		{
            subscriber = new OnMsgEvent(NullEvent);
		}

	    public void AddEventHandler (OnMsgEvent handler)
	    {
            subscriber += handler;
   	    }

	    public void Send (XmlDocument msg)
	    {
            subscriber(msg);
        }

	    public void Activate ()
	    {
            // this channel is always active
	    }

        private void NullEvent(XmlDocument doc)
        {}
	}
}
